/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/containment
// Copyright( c) 2013.  All Rights Reserved
//
// File:		AETFixedSizeStack.inl
// Author:		Gianluca Belardelli
// Date:		05/10/2013
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AETFIXEDSIZESTACK_INL_
#define _AETFIXEDSIZESTACK_INL_

template <class T>
AE_FORCEINLINE AETFixedSizeStackBase::AETFixedSizeStackBase( T *lpData, AEUINT32 uiSize )
	: m_lpData( lpData ), m_uiDataSize( uiSize ), m_uiSize( 0 ) { }

template <class T>
AE_FORCEINLINE void AETFixedSizeStackBase::Push( const T &tValue )
{
	AEASSERT_MSG( m_uiSize < m_uiDataSize, "Stack overflow!!!" );
	m_lpData[ m_uiSize++ ] = tValue;
}

template <class T>
AE_FORCEINLINE T AETFixedSizeStackBase::Pop( void )
{
	AEASSERT_MSG( m_uiSize > 0, "Errore indice stack" );
	return m_lpData[ --m_uiSize ];
}

template <class T>
AE_FORCEINLINE T &AETFixedSizeStackBase::Top( void )
{
	AEASSERT_MSG( m_uiSize > 0, "Stack vuoto" );
	return m_lpData[ m_uiSize-1 ];
}

template <class T>
AE_FORCEINLINE const T &AETFixedSizeStackBase::Top( void ) const
{
	AEASSERT_MSG( m_uiSize > 0, "Stack vuoto" );
	return m_lpData[ m_uiSize-1 ];
}

template <class T>
AE_FORCEINLINE AEUINT32 AETFixedSizeStackBase::GetSize( void ) const
{
	return m_uiSize;
}

template <class T>
AE_FORCEINLINE T &AETFixedSizeStackBase::operator []( AEUINT32 uiIndex )
{
	AEASSERT_MSG( uiIndex < m_uiSize, "Errore indice stack" );
	return m_lpData[ uiIndex ];
}

template <class T>
AE_FORCEINLINE const T &AETFixedSizeStackBase::operator []( AEUINT32 uiIndex ) const
{
	AEASSERT_MSG( uiIndex < m_uiSize, "Errore indice stack" );
	return m_lpData[ uiIndex ];
}

template<typename T,AEUINT32 size>
AE_FORCEINLINE AETFixedSizeStack( void ) : AETFixedSizeStackBase<T>( m_arrData, size ) { }

#endif // _AETFIXEDSIZESTACK_INL_